package com.sjsu.cmpe239.validations;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Validations 
{
	private static final String EMAIL_PATTERN = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
	private static final String NAME_PATTERN = "^[a-zA-Z][a-zA-Z]*$";
	private static final String PASSWORD_PATTERN = "(?!^[1-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{8,12})$";
	private static Pattern pattern;
	private static Matcher matcher;

	public static boolean validateEmail(String email)
	{
		try
		  {
			  pattern = Pattern.compile(EMAIL_PATTERN);
			  matcher = pattern.matcher(email);
			  return matcher.matches();
		  }
		  catch(Exception e)
		  {
			  System.err.println(e);
			  return false;
		  }
	}
	public static boolean validateName(String name)
	{
		try
		  {
			  pattern = Pattern.compile(NAME_PATTERN);
			  matcher = pattern.matcher(name);
			  return matcher.matches();

		  }
		  catch(Exception e)
		  {
			  System.err.println(e);
			  return false;
		  }
	}
	
	public static boolean validatePassword(String password)
	{
		try
		  {
			  pattern = Pattern.compile(PASSWORD_PATTERN);
			  matcher = pattern.matcher(password);
			  return matcher.matches();
		  }
		  catch(Exception e)
		  {
			  System.err.println(e);
			  return false;
		  }
	}

}
